<template>
  <div class="header fx-v-h">
    <div class="left bold">考试系统</div>
    <div class="right">
      <div v-if="!isLogin">
        请先登录哦
      </div>
      <div v-else class="fx-v-h user cs">
        <span class="username">{{ info.username }}</span>
        <el-dropdown placement="top" @command="handleLogout">
          <span class="el-dropdown-link">
            <img class="avatar br-5" :src="info.avatar" alt="">
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command='logout'>退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  data() {
    return {
      dialogVisible: false,
      registerVisible: false,
    };
  },
  computed: {
    ...mapState(["info", "isLogin"]),
  },
  methods: {
    onClose() {
      this.dialogVisible = false;
    },

    /**
     * 退出登录
     */
    handleLogout(key) {
      if (key === 'logout') {
        this.$store.commit("logout", () => {
          this.$router.push('/index')
        })
      }
    }
  },
};
</script>

<style lang="scss" scoped>
.header {
  width: 100%;
  padding: 0 30px;
  justify-content: space-between;
}
.user {
  .username {
    margin-right: 20px;
  }
}

.avatar {
    display: block;
  height: 40px;
  width: 40px;
}
.left {
  font-size: 20px;
}
</style>
